<template>
  <el-card shadow="never">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <el-form :inline="true" :model="searchModel" size="small">
        <el-form-item label="年份">
          <year-select  v-model="searchModel.year" @change="loadData"></year-select>
        </el-form-item>
        <el-form-item label="合同号">
          <el-input v-model="searchModel.contractNamber" placeholder="合同号"></el-input>
        </el-form-item>
        <el-form-item label="资产名称">
          <el-input v-model="searchModel.name" placeholder="资产名称"></el-input>
        </el-form-item>
        <template v-if="toggleSearchStatus">
          <el-form-item label="批次">
            <el-input v-model="searchModel.batch" placeholder="批次"></el-input>
          </el-form-item>
          <el-form-item label="入库时间">
            <el-col class="dateCol" :span="11">
              <el-date-picker type="date" placeholder="开始时间" v-model="searchModel.inDate_begin" style="width: 100%;"></el-date-picker>
            </el-col>
            <el-col align="center" class="line" :span="1">~</el-col>
            <el-col class="dateCol" :span="11">
              <el-date-picker type="date" placeholder="结束时间" v-model="searchModel.inDate_end" style="width: 100%;"></el-date-picker>
            </el-col>
          </el-form-item>
          <el-form-item label="分类编码">
            <el-input v-model="searchModel.code" placeholder="分类编码"></el-input>
          </el-form-item>
          <el-form-item label="资产大类">
            <el-select v-model="searchModel.classes" placeholder="请选择">
              <el-option key="1" label="土地" :value="1"></el-option>
              <el-option key="2" label="房屋及构筑物" :value="2"></el-option>
              <el-option key="3" label="通用设备" :value="3"></el-option>
              <el-option key="4" label="车辆" :value="4"></el-option>
              <el-option key="5" label="专用设备" :value="5"></el-option>
              <el-option key="6" label="文物及陈列品" :value="6"></el-option>
              <el-option key="7" label="图书档案" :value="7"></el-option>
              <el-option key="8" label="家具用具及装具" :value="8"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="分类名称">
            <el-input v-model="searchModel.typeName" placeholder="分类名称"></el-input>
          </el-form-item>
          <el-form-item label="购买单位">
            <el-input v-model="searchModel.buyer" placeholder="购买单位"></el-input>
          </el-form-item>
        </template>
        <el-form-item>
          <span style="float: left;overflow: hidden;" class>
            <el-button type="primary" @click="searchQuery" icon="el-icon-search">查询</el-button>
            <el-button
              type="primary"
              @click="searchReset"
              icon="el-icon-refresh"
              style="margin-left: 8px"
            >重置</el-button>

            <el-button @click="handleToggleSearch()" type="text" size="small">
              {{ toggleSearchStatus ? '收起' : '展开' }}
              <i
                :class="toggleSearchStatus ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
              ></i>
            </el-button>
          </span>
        </el-form-item>
      </el-form>
    </div>
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <el-button icon="el-icon-download" size="small" class="addBtn" type="primary" @click="handleExportXls('资产折旧表')">导出</el-button>
      <el-button icon="el-icon-printer" size="small" class="addBtn" type="primary" @click="handlePrintXls">打印</el-button>
    </div>
    <!-- 资产列表 -->
    <div class="project">
      <el-table
        border
        size="small"
        :data="dataSource"
        style="width: 100%"
        :header-cell-style="{background:'#eef1f6',color:'#606266'}">
        <el-table-column fixed type="index" width="50" label=""> </el-table-column>
        <el-table-column prop="number" fixed width="170" label="资产ID"></el-table-column>
        <el-table-column prop="name" fixed width="150" label="资产名称" sortable></el-table-column>
        <el-table-column prop="inDate" fixed width="120" label="入库日期" sortable></el-table-column>
        <el-table-column prop="price" fixed width="110" label="原值（元）" sortable></el-table-column>

        <el-table-column label="1月份">
            <el-table-column prop="current_1" label="当期折旧" width="100"></el-table-column>
            <el-table-column prop="sum_1" label="累计折旧" width="100"></el-table-column>
            <el-table-column prop="surplus_1" label="剩余值" width="100"></el-table-column>
        </el-table-column>
        <el-table-column label="2月份">
            <el-table-column prop="current_2" label="当期折旧" width="100"></el-table-column>
            <el-table-column prop="sum_2" label="累计折旧" width="100"></el-table-column>
            <el-table-column prop="surplus_2" label="剩余值" width="100"></el-table-column>
        </el-table-column>
        <el-table-column label="3月份">
            <el-table-column prop="current_3" label="当期折旧" width="100"></el-table-column>
            <el-table-column prop="sum_3" label="累计折旧" width="100"></el-table-column>
            <el-table-column prop="surplus_3" label="剩余值" width="100"></el-table-column>
        </el-table-column>
        <el-table-column label="4月份">
            <el-table-column prop="current_4" label="当期折旧" width="100"></el-table-column>
            <el-table-column prop="sum_4" label="累计折旧" width="100"></el-table-column>
            <el-table-column prop="surplus_4" label="剩余值" width="100"></el-table-column>
        </el-table-column>
        <el-table-column label="5月份">
            <el-table-column prop="current_5" label="当期折旧" width="100"></el-table-column>
            <el-table-column prop="sum_5" label="累计折旧" width="100"></el-table-column>
            <el-table-column prop="surplus_5" label="剩余值" width="100"></el-table-column>
        </el-table-column>
        <el-table-column label="6月份">
            <el-table-column prop="current_6" label="当期折旧" width="100"></el-table-column>
            <el-table-column prop="sum_6" label="累计折旧" width="100"></el-table-column>
            <el-table-column prop="surplus_6" label="剩余值" width="100"></el-table-column>
        </el-table-column>
        <el-table-column label="7月份">
            <el-table-column prop="current_7" label="当期折旧" width="100"></el-table-column>
            <el-table-column prop="sum_7" label="累计折旧" width="100"></el-table-column>
            <el-table-column prop="surplus_7" label="剩余值" width="100"></el-table-column>
        </el-table-column>
        <el-table-column label="8月份">
            <el-table-column prop="current_8" label="当期折旧" width="100"></el-table-column>
            <el-table-column prop="sum_8" label="累计折旧" width="100"></el-table-column>
            <el-table-column prop="surplus_8" label="剩余值" width="100"></el-table-column>
        </el-table-column>
        <el-table-column label="9月份">
            <el-table-column prop="current_9" label="当期折旧" width="100"></el-table-column>
            <el-table-column prop="sum_9" label="累计折旧" width="100"></el-table-column>
            <el-table-column prop="surplus_9" label="剩余值" width="100"></el-table-column>
        </el-table-column>
        <el-table-column label="10月份">
            <el-table-column prop="current_10" label="当期折旧" width="100"></el-table-column>
            <el-table-column prop="sum_10" label="累计折旧" width="100"></el-table-column>
            <el-table-column prop="surplus_10" label="剩余值" width="100"></el-table-column>
        </el-table-column>
        <el-table-column label="11月份">
            <el-table-column prop="current_11" label="当期折旧" width="100"></el-table-column>
            <el-table-column prop="sum_11" label="累计折旧" width="100"></el-table-column>
            <el-table-column prop="surplus_11" label="剩余值" width="100"></el-table-column>
        </el-table-column>
        <el-table-column label="12月份">
            <el-table-column prop="current_12" label="当期折旧" width="100"></el-table-column>
            <el-table-column prop="sum_12" label="累计折旧" width="100"></el-table-column>
            <el-table-column prop="surplus_12" label="剩余值" width="100"></el-table-column>
        </el-table-column>
        <el-table-column fixed="right" prop="state" label="资产状态">
          <template slot-scope="scope">
            {{ ['闲置','已领用','已处置'][scope.row.state-1] }}
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作">
          <template slot-scope="scope">
            <el-button @click="handleDetail(scope.row)" type="text">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        :total="ipagination.total"
        :page.sync="ipagination.current"
        :limit.sync="ipagination.pageSize"
        @pagination="loadData"
      ></pagination>
      <asset-view-modal ref="modalForm"></asset-view-modal>
    </div>
  </el-card>
</template>

<script>
import { SingleTableMixins } from "@/mixins/SingleTableMixins"
import Pagination from "@/components/Pagination"
import YearSelect from '../../../components/YearSelect/index'
import AssetViewModal from '../../assetBusiness/modules/AssetViewModal'
import { deleteAction, getAction,downFile } from '@/api/manage'

export default {
  name: "depreciation",
  mixins: [SingleTableMixins],
  components: { AssetViewModal, YearSelect, Pagination },
  data() {
    return {
      month : new Date().getUTCMonth()+1,
      disableMixinCreated: true,
      url: {
        list: '/asset/depreciation',
        exportXlsUrl:'/asset/depreciationExprot',
        printXlsUrl:'/asset/print'
      },
      // 表单数据选择
      multipleSelection: []
    }
  },
  methods: {
    handlePrintXls(){
      var params = this.getQueryParams();//查询条件
      getAction(this.url.printXlsUrl, params).then((res) => {
        var iframe = document.createElement('IFRAME');
        iframe.setAttribute('style', 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;');
        document.body.appendChild(iframe);
        var doc = iframe.contentWindow.document;
        doc.write(res);
        var ys="html,body{height:100%}img{max-width:100%;max-height:100%;margin:0 auto}";
        var style=document.createElement("style");
        style.innerText=ys;
        doc.getElementsByTagName("head")[0].appendChild(style)
        doc.close();
        iframe.contentWindow.focus();
        iframe.contentWindow.print();
        iframe.remove();
      })
    },
    getSummaries(param){
      const { columns, data } = param;
      const sums = [];

      return sums;
    }
  }
}
</script>

<style scoped>
  >>> .cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>
